package com.mjf.cjt.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.chanjet.openapi.sdk.java.exception.ChanjetApiException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mjf.cjt.config.OpenApiConfig;
import com.mjf.cjt.domain.OrgEntity;
import com.mjf.cjt.domain.PullDataFromCjtRemote;
import com.mjf.cjt.enums.TFApiEnum;
import com.mjf.cjt.util.TMHttpUtils;
import com.mjf.cjt.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * desc 同步T+接口数据
 * </p>
 *
 * @author chenshoumeng
 * @date 2025/3/31 11:08
 */
@Slf4j
@Service
public class AsyncTMService {

    @Autowired
    private OpenApiConfig openApiConfig;
    @Autowired
    private OrgService orgService;
    @Autowired
    private CjtAuthService cjtAuthService;
    @Autowired
    private PullDataFromCjtRemote pullDataFromCjtRemote;
    @Autowired
    private TMHttpUtils httpUtils;


    /**
     * 拉取生成加工单
     */
    public List<ProductOrderVo> getDeliveryOrderFromRemote(String startDate, String endDate) throws ChanjetApiException {
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());
        if (token == null) {
            throw new RuntimeException("token 不存在");
        }
        List<Map<String, String>> resultList = new ArrayList<>();
        //开始时间
        Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", startDate).put("text", startDate).build();
        //结束时间
        Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", endDate).put("text", endDate).build();
        //发货类型为 生产发货
        Map<String, String> typeMap = MapUtil.builder(new HashMap<String, String>()).put("value", "生产发货").put("text", "生产发货").build();
        List<Map<String, String>> dateList = ListUtil.of(
            startDateMap, endDateMap
        );
        List<Map<String, String>> typeList = ListUtil.of(
            typeMap
        );
        Map result = MapUtil.of("ManufactureOrder.VoucherDate", dateList);
        pullDataFromCjtRemote.setToken(token);
        pullDataFromCjtRemote.setParamDic(result);
        pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_MANUFACTURE_ORDER_LIST_URL.getFiledList());
        pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_MANUFACTURE_ORDER_LIST_URL.getUrl());
        pullDataFromCjtRemote.setHttpUtils(httpUtils);
        log.info("=================生成加工单请求数据START================");
        pullDataFromCjtRemote.listFromRemote(0, resultList);
        log.info("=================生成加工单请求数据END================");
        log.info("生成加工单数据条数：{}", resultList.size());
        log.info("生成加工单数据：{}", resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return Collections.emptyList();
        }
        //将map转成实体
        List<ProductOrderVo> orderVos = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e),
            ProductOrderVo.class)).collect(Collectors.toList());
        return orderVos;
    }

    /**
     * 查询销货单列表
     */
    public List<SaleDeliveryVo> getSaleDeliveryOrderFromRemote(String startDate,String endDate) throws ChanjetApiException {
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());
        if (token == null) {
            throw new RuntimeException("token 不存在");
        }
        List<Map<String, String>> resultList = new ArrayList<>();
        //开始时间
        Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", startDate).put("text", startDate).build();
        //结束时间
        Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", endDate).put("text", endDate).build();
        List<Map<String, String>> dateList = ListUtil.of(
            startDateMap, endDateMap
        );
        Map result = MapUtil.of("SaleDelivery.VoucherDate", dateList);
        pullDataFromCjtRemote.setToken(token);
        pullDataFromCjtRemote.setParamDic(result);
        pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_SALE_DELIVERY_ORDER_LIST_URL.getFiledList());
        pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_SALE_DELIVERY_ORDER_LIST_URL.getUrl());
        pullDataFromCjtRemote.setHttpUtils(httpUtils);
        log.info("=================销货单请求数据START================");
        pullDataFromCjtRemote.listFromRemote(0, resultList);
        log.info("=================销货单请求数据END================");
        log.info("销货单数据条数：{}", resultList.size());
        log.info("销货单数据：{}", resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return Collections.emptyList();
        }
        //将map转成实体
        List<SaleDeliveryVo> saleDeliveryVoList = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), SaleDeliveryVo.class)).collect(Collectors.toList());
        log.info("销货单实体 ===>> ：{}", saleDeliveryVoList);
        return saleDeliveryVoList;
    }

    /**
     * 同步仓库档案
     */
    public List<WarehouseVO> asyncCW() {
        List<WarehouseVO> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, HashMap<String, Object>> params = new HashMap<>();
            params.put("param", new HashMap<String, Object>(){{
                put("SelectFields", "");
            }});
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_WAREHOUSE_QUERY_URL.getUrl(),
                JSONObject.toJSONString(params),
                header);
            if (response.isOk()) {
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

                try {
                    JavaType type = objectMapper.getTypeFactory()
                        .constructCollectionType(List.class, WarehouseVO.class);
                    vos = objectMapper.readValue(response.body(), type);
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
            log.info("同步仓库档案成功");
        } catch (Exception e) {
            log.error("同步仓库档案失败");
        }
        return vos;
    }

    /**
     * 存货档案
     */
    public List<InventoryVO.InventoryInfo> asyncCH() {

        List<InventoryVO.InventoryInfo> vos = new ArrayList<>();
        InventoryVO vo = new InventoryVO();
        vo.setData(vos);
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, HashMap<String, Object>> params = new HashMap<>();
            params.put("param", new HashMap<String, Object>(){{
                put("SelectFields", TFApiEnum.TF_API_INVENTORY_QUERY_PAGE_URL.getFiledString());
                put("pageSize", 200);
            }});

            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            boolean isNext = true;
            int page = 1;
            while (isNext) {
                params.get("param").put("pageIndex", page);
                HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_INVENTORY_QUERY_PAGE_URL.getUrl(),
                    JSONObject.toJSONString(params),
                    header);
                if (response.isOk()) {
                    ObjectMapper objectMapper = new ObjectMapper();
                    objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                    try {
                        InventoryVO vo1 = objectMapper.readValue(response.body(), InventoryVO.class);
                        if (CollectionUtil.isNotEmpty(vo1.getData())) {
                            vo.getData().addAll(vo1.getData());
                            page++;
                        } else {
                            isNext = false;
                        }
                    } catch (JsonProcessingException e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    }
                } else {
                    isNext = false;
                    log.error("error {}", response);
                }
            }

            log.info("同步存货档案成功");
        } catch (Exception e) {
            log.error("同步存货档案失败");
        }
        return vo.getData();
    }

    /**
     * 往来单位
     */
    public List<PartnerVO.InfoData> asyncWLDW() {
        List<PartnerVO.InfoData> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, Map<String, Object>> params = new HashMap<>();
            params.put("param", new HashMap<String, Object>(){{
                put("SelectFields", TFApiEnum.TF_API_PARTNER_QUERY_URL.getFiledString());
                put("PageSize", 200);
            }});
            int page = 1;
            boolean isNext = true;

            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            while (isNext) {
                params.get("param").put("PageIndex", page);
                HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_PARTNER_QUERY_URL.getUrl(),
                    JSONObject.toJSONString(params),
                    header);
                if (response.isOk()) {
                    ObjectMapper objectMapper = new ObjectMapper();
                    objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                    log.info("response.body {}", response.body());
                    PartnerVO vo = objectMapper.readValue(response.body(), PartnerVO.class);
                    isNext = page < vo.getTotalpage();
                    page++;
                    vos.addAll(vo.getData());
                } else {
                    isNext = false;
                    log.error("error {}", response);
                }
            }
            log.info("同步往来单位成功");
        } catch (Exception e) {
            log.error("同步往来单位失败", e);
        }
        return vos;
    }

    /**
     * 同步进货单
     */
    public List<PurchaseArrivalVO> asyncJHD(String start, String end) {
        List<PurchaseArrivalVO> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }

            String token = cjtAuthService.getToken(orgEntity.getOrgId());
            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            List<Map<String, String>> resultList = new ArrayList<>();
            //开始时间
            Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", start).put("text", start).build();
            //结束时间
            Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", end).put("text", end).build();
            List<Map<String, String>> dateList = ListUtil.of(
                startDateMap, endDateMap
            );
            Map result = MapUtil.of("TCjtzjbPurchaseArrival.VoucherDate", dateList);
            pullDataFromCjtRemote.setToken(token);
            pullDataFromCjtRemote.setParamDic(result);
            pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_PURCHASE_ORDER_LIST_URL.getFiledList());
            pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_PURCHASE_ORDER_LIST_URL.getUrl());
            pullDataFromCjtRemote.setHttpUtils(httpUtils);
            pullDataFromCjtRemote.listFromRemote(0, resultList);
            if (CollectionUtil.isEmpty(resultList)) {
                return Collections.emptyList();
            }
            //将map转成实体
            vos = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), PurchaseArrivalVO.class)).collect(Collectors.toList());
            log.info("进货单实体 ===>> ：{}", vos);
            return vos;
        } catch (Exception e) {
            log.error("同步进货单失败");
        }
        return vos;
    }

    /**
     * 同步收款单
     */
    public List<ArapReceivePaymentVO> asyncSKD(String start, String end) {
        List<ArapReceivePaymentVO> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }

            String token = cjtAuthService.getToken(orgEntity.getOrgId());
            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            List<Map<String, String>> resultList = new ArrayList<>();
            //开始时间
            Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", start).put("text", start).build();
            //结束时间
            Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", end).put("text", end).build();
            List<Map<String, String>> dateList = ListUtil.of(
                startDateMap, endDateMap
            );
            Map result = MapUtil.of("ArapReceivePayment.VoucherDate", dateList);
            pullDataFromCjtRemote.setToken(token);
            pullDataFromCjtRemote.setParamDic(result);
            pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_RECEIVE_VOUCHER_LIST_URL.getFiledList());
            pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_RECEIVE_VOUCHER_LIST_URL.getUrl());
            pullDataFromCjtRemote.setHttpUtils(httpUtils);
            pullDataFromCjtRemote.listFromRemote(0, resultList);
            if (CollectionUtil.isEmpty(resultList)) {
                return Collections.emptyList();
            }
            //将map转成实体
            vos = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), ArapReceivePaymentVO.class)).collect(Collectors.toList());
            log.info("收款单实体 ===>> ：{}", vos);
            return vos;
        } catch (Exception e) {
            log.error("同步收款单失败");
        }
        return vos;
    }

    /**
     * 入库调整单
     * @param dto
     */
    public TFResultVO asyncRKTZD(InWarehouseAdjustOrderCreateDto dto) {
        /**
         * {
         *     "dto": {
         *         "ExternalCode": "Out0001",
         *         "VoucherDate": "2023-08-23",
         *         "Memo": "测试",
         *         "Warehouse": {
         *             "Code": "01"
         *         },
         *         "AdjustCostDetails": [{
         *                 "Warehouse": {
         *                     "Code": "01"
         *                 },
         *                 "Inventory": {
         *                     "Code": "9901"
         *                 },
         *                 "Amount":2
         *             }
         *         ]
         *     }
         * }
         */
//        InWarehouseAdjustOrderCreateDto.Dto dto1 = new InWarehouseAdjustOrderCreateDto.Dto();
//        dto1.setExternalCode("Out0001");
//        dto1.setVoucherDate("2023-08-23");
//        dto1.setMemo("测试");
//        InWarehouseAdjustOrderCreateDto.WarehouseInfo warehouseInfo = new InWarehouseAdjustOrderCreateDto.WarehouseInfo();
//        warehouseInfo.setCode("01");
//        dto1.setWarehouse(warehouseInfo);
//        InWarehouseAdjustOrderCreateDto.Details details = new InWarehouseAdjustOrderCreateDto.Details();
//        details.setAmount(BigDecimal.valueOf(12));
//        InWarehouseAdjustOrderCreateDto.InventoryInfo inventoryInfo = new InWarehouseAdjustOrderCreateDto.InventoryInfo();
//        inventoryInfo.setCode("9901");
//        details.setInventory(inventoryInfo);
//        details.setWarehouse(warehouseInfo);
//        List<InWarehouseAdjustOrderCreateDto.Details> detailsList = new ArrayList<>();
//        detailsList.add(details);
//        dto1.setAdjustCostDetails(detailsList);
//        dto.setDto(dto1);
        TFResultVO vo = new TFResultVO();
        vo.setCode("-1");
        vo.setMessage(TFApiEnum.TF_API_ADJUST_COST_IN_CREATE_URL.getName() + "接口调用错误");
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_ADJUST_COST_IN_CREATE_URL.getUrl(),
                JSONObject.toJSONString(dto),
                header);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            vo = objectMapper.readValue(response.body(), TFResultVO.class);

        } catch (Exception e) {
            log.error("入库调整单创建失败");
        }
        return vo;
    }

    /**
     * 同步员工
     */
    public List<TFPersonVO> asyncYG() {
        List<TFPersonVO> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, HashMap<String, Object>> params = new HashMap<>();
            params.put("dto", new HashMap<String, Object>(){{
                put("SelectFields", TFApiEnum.TF_API_PERSON_QUERY_URL.getFiledString());
            }});

            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_PERSON_QUERY_URL.getUrl(),
                JSONObject.toJSONString(params),
                header);
            if (response.isOk()) {
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                JavaType type = objectMapper.getTypeFactory()
                    .constructCollectionType(List.class, TFPersonVO.class);
                vos = objectMapper.readValue(response.body(), type);
            } else {
                log.error("error {}", response);
            }
            log.info("同步员工成功");
        } catch (Exception e) {
            log.error("同步员工失败");
        }
        return vos;
    }

    /**
     * 费用档案
     */
    public List<ExpenseVO> asyncFYDA() {
        List<ExpenseVO> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, HashMap<String, Object>> params = new HashMap<>();
            params.put("dto", new HashMap<String, Object>(){{}});

            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_EXPENSE_QUERY_URL.getUrl(),
                JSONObject.toJSONString(params),
                header);
            if (response.isOk()) {
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                JavaType type = objectMapper.getTypeFactory()
                    .constructCollectionType(List.class, ExpenseVO.class);
                vos = objectMapper.readValue(response.body(), type);
            } else {
                log.error("error {}", response);
            }
            log.info("同步费用档案成功");
        } catch (Exception e) {
            log.error("同步费用档案失败");
        }
        return vos;
    }

    /**
     * 同步部门档案
     * @return
     * @throws ChanjetApiException
     */
    public List<DepartResultVO> syncDepart() throws ChanjetApiException {
        List<DepartResultVO> vo = new ArrayList<>();
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }
        String token = cjtAuthService.getToken(orgEntity.getOrgId());

        if (token == null) {
            throw new RuntimeException("token 不存在");
        }

        Map<String, String> header = new HashMap<>();
        header.put("openToken", token);
        Map<String, HashMap<String, Object>> params = new HashMap<>();
        params.put("dto", new HashMap<String, Object>(){{
            put("SelectFields", TFApiEnum.TF_API_DEPARTMENT_QUERY_URL.getFiledString());
        }});

        HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_DEPARTMENT_QUERY_URL.getUrl(),
            JSONObject.toJSONString(params),
            header);
        if (response.isOk()) {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            try {
                JavaType type = objectMapper.getTypeFactory()
                    .constructCollectionType(List.class, DepartResultVO.class);
                vo = objectMapper.readValue(response.body(), type);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        log.info("同步部门档案成功");
        return vo;
    }
    /**
     * 构建凭证查询参数
     * @param startDate
     * @param endDate
     * @param page
     * @return
     */
    public String buildVoucherQueryParams(String startDate, String endDate, Integer page) {
        Map<String, Object> params = new HashMap<>();
        List<Map<String, Object>> dtosList = new ArrayList<>();
        dtosList.add(new HashMap<String, Object>(){{
            put("VoucherDate", startDate);
            put("pagesize", 100);
            put("pageindex", page);
        }});
        dtosList.add(new HashMap<String, Object>(){{
            put("VoucherDate", endDate);
            put("pagesize", 100);
            put("pageindex", page);
        }});
        params.put("dtos", dtosList);
        return JSONObject.toJSONString(params);
    }
    /**
     * 同步凭证
     * @return VoucherResultVO 返回凭证数据
     */
    public VoucherResultVO syncVoucher(String start, String end) throws ChanjetApiException {

        VoucherResultVO vo = new VoucherResultVO();
        vo.setRows(new ArrayList<>());
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());

        if (token == null) {
            throw new RuntimeException("token 不存在");
        }

        Map<String, String> header = new HashMap<>();
        header.put("openToken", token);
        boolean isNext = true;
        int page = 0;
        while (isNext) {
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_VOUCHER_QUERY_URL.getUrl(),
                buildVoucherQueryParams(start, end, page),
                header);
            if (response.isOk()) {
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                try {
                    VoucherResultVO vo1 = objectMapper.readValue(response.body(), VoucherResultVO.class);
                    if (CollectionUtil.isNotEmpty(vo1.getRows())) {
                        vo.getRows().addAll(vo1.getRows());
                        page++;
                    } else {
                        isNext = false;
                    }
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            } else {
                isNext = false;
                log.error("error {}", response);
            }
        }
        log.info("同步凭证成功");
        return vo;
    }
    /**
     * 构建项目档案查询参数
     * @return
     */
    public String buildProjectQueryParams() {
        Map<String, Object> params = new HashMap<>();
        params.put("param", new HashMap<String, Object>(){{
            put("pageSize", 1000);
        }});
        return JSONObject.toJSONString(params);
    }
    /**
     * 同步项目档案
     */
    public List<ProjectResultVO> syncProject() throws ChanjetApiException {

        List<ProjectResultVO> vo = new ArrayList<>();
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }
        String token = cjtAuthService.getToken(orgEntity.getOrgId());

        if (token == null) {
            throw new RuntimeException("token 不存在");
        }

        Map<String, String> header = new HashMap<>();
        header.put("openToken", token);
        HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_PROJECT_QUERY_URL.getUrl(), buildProjectQueryParams(),
            header);
        if (response.isOk()) {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            try {
                JavaType type = objectMapper.getTypeFactory()
                    .constructCollectionType(List.class, ProjectResultVO.class);
                vo = objectMapper.readValue(response.body(), type);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        log.info("同步项目档案成功");
        return vo;
    }

    /**
     * 构建科目档案查询参数
     * @return
     */
    public String buildAccountQueryParams(Integer page) {
        Map<String, Object> params = new HashMap<>();
        params.put("dto", new HashMap<String, Object>(){{
            put("accountingYear", -1);
            put("pageSize", 1000);
            put("pageIndex", page);
        }});
        return JSONObject.toJSONString(params);
    }

    /**
     * 同步科目档案
     */
    public AccountResultVO syncAccount() throws ChanjetApiException {

        AccountResultVO vo = new AccountResultVO();
        AccountResultVO.ADataTable dataTable = new AccountResultVO.ADataTable();
        dataTable.setRows(new ArrayList<>());
        vo.setDataTable(dataTable);
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }
        String token = cjtAuthService.getToken(orgEntity.getOrgId());

        if (token == null) {
            throw new RuntimeException("token 不存在");
        }

        Map<String, String> header = new HashMap<>();
        header.put("openToken", token);
        boolean isNext = true;
        int page = 1;
        while (isNext) {
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_ACCOUNT_QUERY_URL.getUrl(),
                buildAccountQueryParams(page),
                header);
            if (response.isOk()) {
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                try {
                    AccountResultVO vo1 = objectMapper.readValue(response.body(), AccountResultVO.class);
                    if (ObjectUtil.isNotNull(vo1.getDataTable()) && CollectionUtil.isNotEmpty(vo1.getDataTable().getRows())) {
                        vo.getDataTable().getRows().addAll(vo1.getDataTable().getRows());
                        page++;
                    } else {
                        isNext = false;
                    }
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            } else {
                isNext = false;
                log.error("error {}", response);
            }
        }
        log.info("同步科目档案成功");
        return vo;
    }

    /**
     * 同步T+分类
     */
    public List<TFClassVO> asyncFL() {

        List<TFClassVO> vos = new ArrayList<>();
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, HashMap<String, Object>> params = new HashMap<>();
            params.put("param", new HashMap<String, Object>(){{
                put("SelectFields", TFApiEnum.TF_API_INVENTORY_CLASS_QUERY_URL.getFiledString());
            }});

            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_INVENTORY_CLASS_QUERY_URL.getUrl(),
                JSONObject.toJSONString(params),
                header);
            if (response.isOk()) {
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
                JavaType type = objectMapper.getTypeFactory()
                    .constructCollectionType(List.class, TFClassVO.class);
                vos = objectMapper.readValue(response.body(), type);
            } else {
                log.error("error {}", response);
            }
            log.info("同步分类档案成功");
        } catch (Exception e) {
            log.error("同步分类档案失败", e);
        }
        return vos;
    }

    /**
     * 推送T+费用单
     * @param vo
     * @throws ChanjetApiException
     */
    public TFResultVO pushExpenseVoucher(ExpenseVoucherCreateVO vo) throws ChanjetApiException {
        TFResultVO resultVO = new TFResultVO();
        resultVO.setCode("-1");
//        resultVO.setMessage(TFApiEnum.TF_API_ADJUST_COST_IN_CREATE_URL.getName() + "接口调用错误");
        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);

            Map<String, Object> params = new HashMap<>();
            Map<String, Object> dto = new HashMap<>();
            dto.put("VoucherDate", vo.getVoucherDate());
            dto.put("ExternalCode", vo.getExternalCode());
            dto.put("BusinessType", new HashMap<String, Object>(){{
                put("code", vo.getBusinessType().getCode());
            }});
            dto.put("billType", new HashMap<String, Object>(){{
                put("code", vo.getBillType().getCode());
            }});
            dto.put("Partner", new HashMap<String, Object>(){{
                put("code", vo.getPartner().getCode());
            }});
            List<Map<String, Object>> details = new ArrayList<>();
            for (ExpenseVoucherCreateVO.DetailVO detailVO : vo.getDetails()) {
                Map<String, Object> detail = new HashMap<>();
                detail.put("expenseitem", new HashMap<String, Object>(){{
                    put("code", detailVO.getExpenseitemCode());
                }});
                detail.put("TaxRate", detailVO.getTaxRate());
                detail.put("OrigAmount", detailVO.getOrigAmount());
                detail.put("OrigTax", detailVO.getOrigTax());
                detail.put("OrigTaxAmount", detailVO.getOrigTaxAmount());
                detail.put("expenseItemUse", detailVO.getExpenseItemUse());
                details.add(detail);
            }
            dto.put("Details", details);
            dto.put("dto", vo);
            params.put("dto", dto);

            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_EXPENSE_VOUCHER_CREATE_URL.getUrl(),
                JSONObject.toJSONString(params),
                header);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            resultVO = objectMapper.readValue(response.body(), TFResultVO.class);

        } catch (Exception e) {
            log.error("入库调整单创建失败", e);
        }
        return resultVO;
    }

    /**
     * 推送T+产成品入库单
     */
    public TFResultVO pushArrivalCreate(ProductReceiveCreateVO vo) throws ChanjetApiException {

        TFResultVO resultVO = new TFResultVO();
        resultVO.setCode("-1");
        resultVO.setMessage(TFApiEnum.TF_API_PRODUCT_RECEIVE_CREATE_URL.getName() + "接口调用错误");

        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            Map<String, Object> params = new HashMap<>();
            Map<String, Object> dto = new HashMap<>();
            dto.put("Code", vo.getExternalCode());
            dto.put("ExternalCode", vo.getExternalCode());
            dto.put("VoucherType", new HashMap<String, Object>(){{
                put("Code", vo.getVoucherTypeCode());
            }});
            dto.put("VoucherDate", vo.getVoucherDate());
            dto.put("BusiType", new HashMap<String, Object>(){{
                put("Code", vo.getBusiTypeCode());
            }});
            dto.put("RdStyle", new HashMap<String, Object>(){{
                put("Code", vo.getRdStyleCode());
            }});
            dto.put("Warehouse", new HashMap<String, Object>(){{
                put("Code", vo.getWarehouseCode());
            }});
            List<Map<String, Object>> rdrecordDetails = new ArrayList<>();
            for (ProductReceiveCreateVO.Details details : vo.getDetails()) {
                rdrecordDetails.add(new HashMap<String, Object>(){{
                    put("Code", details.getRowCode());
                    put("Inventory", new HashMap<String, Object>(){{
                        put("Code", details.getInventoryCode());
                    }});
                    put("BaseQuantity", details.getQuantity());
                }});
            }
            dto.put("RdRecordDetails", rdrecordDetails);

            params.put("dto", dto);
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_PRODUCT_RECEIVE_CREATE_URL.getUrl(),
                JSONObject.toJSONString(params),
                header);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            resultVO = objectMapper.readValue(response.body(), TFResultVO.class);
            resultVO.setResult(response.body());

        } catch (Exception e) {
            log.error("产成品入库单创建失败", e);
        }

        return resultVO;
    }

    /**
     * 推送T+其他入库单
     */
    public TFResultVO otherInStockOrder(TOtherInStockOrderCreateVo vo) throws ChanjetApiException {

        TFResultVO resultVO = new TFResultVO();
        resultVO.setCode("-1");
        resultVO.setMessage(TFApiEnum.TF_API_PRODUCT_RECEIVE_CREATE_URL.getName() + "接口调用错误");

        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            Map<String, Object> params = new HashMap<>();
            params.put("dto", vo);
            ObjectMapper mapper = new ObjectMapper();
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_OTHER_IN_STOCK_ORDER_CREATE_URL.getUrl(),
                    mapper.writeValueAsString(vo),
                    header);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            resultVO = objectMapper.readValue(response.body(), TFResultVO.class);
            resultVO.setResult(response.body());

        } catch (Exception e) {
            log.error("产成品入库单创建失败", e);
        }

        return resultVO;
    }

    /**
     * 推送T+进货单
     */
    public TFResultVO pushArrivalCreate(PushArrivalCreateVO vo) throws ChanjetApiException {

        TFResultVO resultVO = new TFResultVO();
        resultVO.setCode("-1");
        resultVO.setMessage(TFApiEnum.TF_API_PUR_ARRIVAL_CREATE_URL.getName() + "接口调用错误");

        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            Map<String, Object> params = new HashMap<>();
            params.put("dto", vo);
            ObjectMapper mapper = new ObjectMapper();
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_PUR_ARRIVAL_CREATE_URL.getUrl(),
                    mapper.writeValueAsString(vo),
                    header);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            resultVO = objectMapper.readValue(response.body(), TFResultVO.class);
            resultVO.setResult(response.body());

        } catch (Exception e) {
            log.error(TFApiEnum.TF_API_PUR_ARRIVAL_CREATE_URL.getName() + "创建失败", e);
        }

        return resultVO;
    }

    /**
     * 销售出库单列表查询
     * @param startDate
     * @param endDate
     * @return
     * @throws ChanjetApiException
     */
    public List<SaleDispatchVo> getSaleDispatchOrderFromRemote(String startDate,String endDate) throws ChanjetApiException {
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());
        if (token == null) {
            throw new RuntimeException("token 不存在");
        }
        List<Map<String, String>> resultList = new ArrayList<>();
        //开始时间
        Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", startDate).put("text", startDate).build();
        //结束时间
        Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", endDate).put("text", endDate).build();
        List<Map<String, String>> dateList = ListUtil.of(
            startDateMap, endDateMap
        );
        Map result = MapUtil.of("RDRecord.VoucherDate", dateList);
        pullDataFromCjtRemote.setToken(token);
        pullDataFromCjtRemote.setParamDic(result);
        pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_SALES_OUT_LIST_URL.getFiledList());
        pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_SALES_OUT_LIST_URL.getUrl());
        pullDataFromCjtRemote.setHttpUtils(httpUtils);
        log.info("=================销售出库单列表查询请求数据START================");
        pullDataFromCjtRemote.listFromRemote(0, resultList);
        log.info("=================销售出库单列表查询请求数据END================");
        log.info("销售出库单列表查询数据条数：{}", resultList.size());
        log.info("销售出库单列表查询数据：{}", resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return Collections.emptyList();
        }
        //将map转成实体
        List<SaleDispatchVo> saleDispatchVoList = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), SaleDispatchVo.class)).collect(Collectors.toList());
        log.info("销售出库单列表查询实体 ===>> ：{}", saleDispatchVoList);
        return saleDispatchVoList;
    }

    /**
     * 销售订单列表同步
     *
     * @return
     * @throws ChanjetApiException
     */
    public List<SaleOrderVo> getSaleOrderFromRemote(String startDate,String endDate) throws ChanjetApiException {
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());
        if (token == null) {
            throw new RuntimeException("token 不存在");
        }
        List<Map<String, String>> resultList = new ArrayList<>();
        //开始时间
        Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", startDate).put("text", startDate).build();
        //结束时间
        Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", endDate).put("text", endDate).build();

        List<Map<String, String>> dateList = ListUtil.of(
            startDateMap, endDateMap
        );
        Map result = MapUtil.of("SaleOrder.VoucherDate", dateList);

        pullDataFromCjtRemote.setToken(token);
        pullDataFromCjtRemote.setParamDic(result);
        pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_SALES_ORDER_LIST_URL.getFiledList());
        pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_SALES_ORDER_LIST_URL.getUrl());
        pullDataFromCjtRemote.setHttpUtils(httpUtils);
        log.info("=================销售订单列表同步请求数据START================");
        pullDataFromCjtRemote.listFromRemote(0, resultList);
        log.info("=================销售订单列表同步请求数据END================");
        log.info("销售订单列表同步数据条数：{}", resultList.size());
        log.info("销售订单列表同步数据：{}", resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return Collections.emptyList();
        }
        //将map转成实体
        List<SaleOrderVo> saleOrderVoList = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), SaleOrderVo.class)).collect(Collectors.toList());
        log.info("销售订单列表同步实体 ===>> ：{}", saleOrderVoList);
        return saleOrderVoList;
    }

    /**
     * 费用单列表同步
     *
     * @return
     * @throws ChanjetApiException
     */
    public List<ExpensevoucherVo> getExpensevoucherFromRemote(String startDate,String endDate) throws ChanjetApiException {
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());
        if (token == null) {
            throw new RuntimeException("token 不存在");
        }
        List<Map<String, String>> resultList = new ArrayList<>();
        //开始时间
        Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", startDate).put("text", startDate).build();
        //结束时间
        Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", endDate).put("text", endDate).build();

        List<Map<String, String>> dateList = ListUtil.of(
                startDateMap, endDateMap
        );
        Map result = MapUtil.of("ExpenseVoucher.VoucherDate", dateList);

        pullDataFromCjtRemote.setToken(token);
        pullDataFromCjtRemote.setParamDic(result);
        pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_EXPENSE_VOUCHER_LIST_URL.getFiledList());
        pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_EXPENSE_VOUCHER_LIST_URL.getUrl());
        pullDataFromCjtRemote.setHttpUtils(httpUtils);
        log.info("=================费用单列表同步请求数据START================");
        pullDataFromCjtRemote.listFromRemote(0, resultList);
        log.info("=================费用单列表同步请求数据END================");
        log.info("费用单列表同步数据条数：{}", resultList.size());
        log.info("费用单列表同步数据：{}", resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return Collections.emptyList();
        }
        //将map转成实体
        List<ExpensevoucherVo> expensevoucherVoVoList = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), ExpensevoucherVo.class)).collect(Collectors.toList());
        log.info("费用单列表同步实体 ===>> ：{}", expensevoucherVoVoList);
        return expensevoucherVoVoList;
    }

    /**
     * 采购订单列表同步
     *
     * @return
     * @throws ChanjetApiException
     */
    public List<PurchaseOrderVo> getPurchaseOrderFromRemote(String startDate,String endDate) throws ChanjetApiException {
        OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());

        if (orgEntity == null) {
            throw new RuntimeException("未配置org");
        }

        String token = cjtAuthService.getToken(orgEntity.getOrgId());
        if (token == null) {
            throw new RuntimeException("token 不存在");
        }
        List<Map<String, String>> resultList = new ArrayList<>();
        //开始时间
        Map<String, String>  startDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", startDate).put("text", startDate).build();
        //结束时间
        Map<String, String> endDateMap = MapUtil.builder(new HashMap<String, String>()).put("value", endDate).put("text", endDate).build();

        List<Map<String, String>> dateList = ListUtil.of(
                startDateMap, endDateMap
        );
        Map result = MapUtil.of("PurchaseOrder.VoucherDate", dateList);

        pullDataFromCjtRemote.setToken(token);
        pullDataFromCjtRemote.setParamDic(result);
        pullDataFromCjtRemote.setInitSelectFields(TFApiEnum.TF_API_PUR_ORDER_LIST_URL.getFiledList());
        pullDataFromCjtRemote.setPath(TFApiEnum.TF_API_PUR_ORDER_LIST_URL.getUrl());
        pullDataFromCjtRemote.setHttpUtils(httpUtils);
        log.info("=================采购订单列表同步请求数据START================");
        pullDataFromCjtRemote.listFromRemote(0, resultList);
        log.info("=================采购订单列表同步请求数据END================");
        log.info("采购订单列表同步数据条数：{}", resultList.size());
        log.info("采购订单列表同步数据：{}", resultList);
        if (CollectionUtil.isEmpty(resultList)) {
            return Collections.emptyList();
        }
        //将map转成实体
        List<PurchaseOrderVo> PurchaseOrderVoList = resultList.stream().map(e -> JSON.parseObject(JSON.toJSONString(e), PurchaseOrderVo.class)).collect(Collectors.toList());
        log.info("采购订单列表同步实体 ===>> ：{}", PurchaseOrderVoList);
        return PurchaseOrderVoList;
    }

    /**
     * 畅捷通T+销货单创建中间表对照
     */
    public TFResultVO tCjtzjbSaleDelivery(TCjtzjbSaleDeliveryCreateVo vo) throws ChanjetApiException {

        TFResultVO resultVO = new TFResultVO();
        resultVO.setCode("-1");
        resultVO.setMessage(TFApiEnum.TF_API_PRODUCT_RECEIVE_CREATE_URL.getName() + "接口调用错误");

        try {
            OrgEntity orgEntity = orgService.getOrg(openApiConfig.getOrgId());
            if (orgEntity == null) {
                throw new RuntimeException("未配置org");
            }
            String token = cjtAuthService.getToken(orgEntity.getOrgId());

            if (token == null) {
                throw new RuntimeException("token 不存在");
            }
            Map<String, String> header = new HashMap<>();
            header.put("openToken", token);
            Map<String, Object> params = new HashMap<>();
            params.put("dto", vo);
            ObjectMapper mapper = new ObjectMapper();
            log.info(mapper.writeValueAsString(vo));
            HttpResponse response = httpUtils.doPost(TFApiEnum.TF_API_SALE_DELIVERY_CREATE_URL.getUrl(),
                    mapper.writeValueAsString(vo),
                    header);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            resultVO = objectMapper.readValue(response.body(), TFResultVO.class);
            resultVO.setResult(response.body());

        } catch (Exception e) {
            log.error("销货单创建失败", e);
        }

        return resultVO;
    }

}
